import json
import logging

from config import BASE_LJ

from bs4 import BeautifulSoup


def common_assert(TestName, resp, ex_status_code, ex_status, ex_tion):
    resp_json = resp.json()
    TestName.assertEqual(ex_status_code, resp.status_code)
    TestName.assertEqual(ex_status, resp_json['status'])
    TestName.assertIn(ex_tion, resp_json['description'])


def read_json(filename, apiname):
    file_path = BASE_LJ + '/data/' + filename + '.json'
    with open(file_path, 'r', encoding='utf8') as f:
        temp = json.load(f)
        data_temp = temp[apiname]
        api_list = []
        for i in data_temp:
            api_list.append(tuple(i.values()))
        print(api_list)
        return api_list


def html_utils(resp):
    data = resp.json()['description']['form']
    logging.info(f'第三方开户的数据 = {data}')
    bs = BeautifulSoup(data, 'html.parser')
    url = bs.form['action']
    dict_a = {}
    for i in bs.find_all('input'):
        key = i['name']
        value = i['value']
        dict_a[key] = value
    logging.info(f'第三方开户的url = {url},请求题的数据 = {dict_a}')
    return [url, dict_a]


if __name__ == '__main__':
    read_json('login_test', 'get_zc_ok')
